<div class="header_menu">
    <div class="container">
        <div class="header-nav clearfix">
            <?php echo $this->partial('shop/layout/headerMenu'); ?>
        </div>
    </div>
</div>
</div>

<script type="text/javascript" src="<?php echo $this->basePath('template/pc/default/js/jqzoom/js/jquery.jqzoom-core.js'); ?>"></script>
<link href="<?php echo $this->basePath('template/pc/default/js/jqzoom/css/jquery.jqzoom.css'); ?>" rel="stylesheet">
<style type="text/css">
    ul#thumblist li{float:left;padding-right:2px;list-style:none;}
    ul#thumblist li a{display:block;border:1px solid #CCC;}
    ul#thumblist li a.zoomThumbActive{
        border:1px solid red;
    }
</style>

<div class="container breadcrumbs">
    <?php
    $classMenu = $this->shopHelper()->helperPartial('goodsListHelper', 1, $this->inClassInfo);
    echo $this->partial($classMenu['partialFile'], $classMenu['partialArg']);
    ?>
    <a href="<?php echo $this->url('shop-class', ['action'=>'goodsList', 'id' => $this->inClassInfo->getClassId()]); ?>"><?php echo $this->escapeHtml($this->inClassInfo->getClassName()); ?></a><span class="sep">/</span>
    <span><?php echo $this->escapeHtml($this->goodsInfo[0]->getGoodsName()); ?></span>
</div>

<div class="goods-detail container">
    <div class="goods-detail-info row clearfix">
        <div id="goods-part-body">
            <?php echo $this->partial('shop/goods/'.$this->ajaxGoodsPartFile, [
                'classId' => $this->classId,
                'inClassInfo' => $this->inClassInfo,
                'goodsInfo' => $this->goodsInfo,
                'goodsImages' => $this->goodsImages,
                'specImages' => $this->specImages,
                'specGoodsInfo' => $this->specGoodsInfo,
                'userGroup' => $this->userGroup,
                'goodsCustom' => $this->goodsCustom,
                'goodsWholesaleList' => $this->goodsWholesaleList,
                'goodsSpec' => $this->goodsSpec,
                'selectedSpecTagId' => $this->selectedSpecTagId,
                'showData' => $this->showData
        ]); ?>
        </div>

        <div class="span5">
            <div style="border: 1px solid #ed6343;">
                <div style="background-color: #ed6343;padding: 5px;color: #fff;">
                    <strong>&nbsp;<?php echo $this->translate('品质保证'); ?></strong>
                </div>
                <div style="min-height:50px; font-size: 13px; padding: 8px;"><?php echo nl2br($this->escapeHtml($this->shopHelper()->shop('goods_quality', 'content'))); ?></div>
            </div>

            <div style="padding-top: 6px;">
                <div>
                    <?php echo $this->partial($this->goodsPartial[1]['partialFile'], $this->goodsPartial[1]['partialArg']); ?>
                </div>
            </div>
        </div>

    </div>

    <div class="row goods-detail-desc">
        <div class="span5">
            <div class="xm-box goods-alsobuy xm-goods-side-list">
                <div class="box-hd">
                    <div class="title"><?php echo $this->translate('相关商品'); ?></div>
                </div>
                <div class="box-bd">
                    <?php $randGoods = $this->shopHelper()->getShopRandGoods($this->goodsInfo[0]->getGoodsId()); ?>
                    <ul>
                        <?php if ($randGoods) foreach ($randGoods as $rGoodsValue) { ?>
                        <li>
                            <a href="<?php echo $this->url('shop-goods', ['id' => $rGoodsValue[0]->getGoodsId()]); ?>" title="<?php echo $this->escapeHtml($rGoodsValue[0]->getGoodsName()); ?>">
                                <h2><?php echo $this->escapeHtml($rGoodsValue[0]->getGoodsName()); ?></h2>
                                <h2 style="color: #ed6343;font-weight: bold;"><?php echo (isset($rGoodsValue['goodsGroupPrice']) && $rGoodsValue['goodsGroupPrice'] > 0) ? $this->frontCurrency($rGoodsValue['goodsGroupPrice']) : $this->frontCurrency($rGoodsValue[0]->getGoodsPrice()); ?></h2>
                                <div class="star">&nbsp;</div>
                                <img src="" data-original="<?php echo $this->shopHelper()->baseGoodsImagePath($rGoodsValue['goodsThumbnailImage']); ?>" alt="<?php echo $this->escapeHtml($rGoodsValue[0]->getGoodsName()); ?>" class="lazy leftImg">
                            </a>
                        </li>
                        <?php } ?>
                    </ul>
                </div>
            </div>
        </div>

        <div class="span15">
            <div id="goodsDetail" class="xm-box goods-detail-box">
                <div class="box-hd" id="sticky_navigation">
                    <ul class="items clearfix J_pro_related_btns">
                        <li class="current">
                            <a href="#goodsDesc"><?php echo $this->translate('详细信息'); ?></a>
                        </li>
                        <li>
                            <a href="#goodsComment"><?php echo $this->translate('商品评价'); ?></a>
                        </li>
                        <?php if($this->shopHelper()->shop('goods_consultation_state', 'goods') == 1) { ?>
                        <li>
                            <a href="#goodsFaq"><?php echo $this->translate('商品咨询'); ?></a>
                        </li>
                        <?php } ?>
                        <li>
                            <a href="#serQue"><?php echo $this->translate('售后服务'); ?></a>
                        </li>
                        <li>
                            <a href="#goodsBuyQue"><?php echo $this->translate('如何购买'); ?></a>
                        </li>
                    </ul>
                </div>
                <?php if(isset($this->goodsAttribute)) { ?>
                    <div id="goodsParam" class="edit_table_css" style="padding-top: 8px;">
                        <div>
                            <table style="width: 100%;">
                                <tbody>
                                <?php
                                $b_num = count($this->goodsAttribute)-1;
                                foreach($this->goodsAttribute as $b_key => $b_val) {
                                    $b_y_num = $b_key%3; if ($b_key == 0) echo '<tr>';
                                    if ($b_y_num==0 and $b_key!=0) echo '</tr><tr>';
                                    if ($b_num==$b_key) {
                                        ?>

                                        <td width="<?php echo 33*(3-$b_y_num); ?>%" colspan="<?php echo (3-$b_y_num); ?>"><?php echo $b_val; ?></td>
                                        </tr>
                                    <?php } else { ?>

                                        <td width="33%"><?php echo $b_val; ?></td>
                                        <?php
                                    }
                                }
                                ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                <?php } ?>
                <div id="goodsDesc" class="box-bd edit_table_css">
                    <?php if($this->goodsCommonContent) foreach ($this->goodsCommonContent as $contentValue) { echo $this->shopHelper()->shopBody($contentValue->getContentBody(), 'goods'); } ?>

                    <?php echo $this->shopHelper()->shopBody($this->goodsInfo[0]->getGoodsBody(), 'goods'); ?>
                </div>
            </div>
            <div id="goodsComment" class="xm-box goods-detail-comment ">
                <div class="box-hd">
                    <div class="title">
                        <?php echo $this->translate('商品评价'); ?>
                    </div>
                </div>
                <div id="J_goods_detail_comment" class="box-bd">
                    <div class="com-body" id="listGoodsComment"></div>
                </div>
            </div>
            <?php if($this->shopHelper()->shop('goods_consultation_state', 'goods') == 1) { ?>
                <div id="goodsFaq" class="xm-box goods-detail-faq">
                    <div class="box-hd">
                        <div class="title"><?php echo $this->translate('商品咨询'); ?></div>
                    </div>
                    <div class="box-bd">
                        <div id="listGoodsAsk"></div>
                        <?php
                        $cForm = $this->consultForm;
                        $cForm->prepare();

                        echo $this->form()->openTag($cForm);
                        ?>
                        <div class="faq-input">
                            <?php echo $this->formElement($cForm->get('shopCsrf')); ?>
                            <?php echo $this->formElementErrors($cForm->get('shopCsrf'), ['class'=>'error-message']); ?>

                            <?php echo $this->formElement($cForm->get('consultGoodsId')); ?>
                            <?php echo $this->translate('您的问题'); ?>
                            <?php echo $this->formElement($cForm->get('consultContent')->setAttributes(['class' => 'input-content', 'rows' => 5, 'placeholder' => $this->translate('在这里输入您想咨询的问题')])); ?>
                            <?php echo $this->formElementErrors($cForm->get('consultContent'), ['class'=>'error-message']); ?>
                            <button type="submit" class="btn btn-primary ques-btn J_mi_ask"><?php echo $this->translate('提交咨询'); ?></button>
                            <?php if($this->shopHelper()->shop('goods_ask_captcha', 'captcha') == 1) { ?>
                                <br>
                                <?php echo $this->formElement($cForm->get('consultCaptcha')->setAttributes(['class' => 'form-control', 'placeholder' => $this->translate('输入上面的验证码')])); ?>
                                <?php echo $this->formElementErrors($cForm->get('consultCaptcha'), ['class'=>'error-message']); ?>
                            <?php } ?>
                        </div>
                        <?php echo $this->form()->closeTag(); ?>
                    </div>
                </div>
            <?php } ?>
            <div id="serQue" class="common-question">
                <div class="question-hd clearfix">
                    <div class="title_a"><?php echo $this->translate('售后服务'); ?></div>
                </div>
                <div class="question-bd">
                    <?php echo $this->shopHelper()->shop('sales_service', 'content'); ?>
                </div>
            </div>
            <div id="goodsBuyQue" class="common-question" style="margin-top: 30px;">
                <div class="question-hd clearfix">
                    <div class="title_a"><?php echo $this->translate('如何购买'); ?></div>
                </div>
                <div class="question-bd">
                    <?php echo $this->shopHelper()->shop('buy_service', 'content'); ?>
                </div>
            </div>

        </div>
    </div>

</div>


<script type="text/javascript">
    $(document).on('click', '#add_cart_submit', function(event) {
        goodsAddCart();
    });

    function goodsAddCart() {
        $.ajax({
            url: '<?php echo $this->url('shop-cart', ['action'=>'add']); ?>',
            type: 'post',
            dataType: 'json',
            data: $('#addGoodsCartForm').formSerialize(),
            success: function(data) {
                showMessage(data.message);
                if(data.status == 'true') {
                    if (data.hasOwnProperty('toUrl')) return window.location.href = data.toUrl;
                    //if(!data.hasOwnProperty('inSpecGoods')) $('.cart-total').show();
                } else {
                    if(data.hasOwnProperty('loginStatus') && data.loginStatus == 'false') {
                        return window.location.href = '<?php echo $this->url('shop-home'); ?>';
                    }
                }
            }
        });
    }
    $(document).on('click', '#buy_now_submit', function(event) {
        $.ajax({
            url: '<?php echo $this->url('shop-cart', ['action'=>'addBuyNow']); ?>',
            type: 'post',
            dataType: 'json',
            data: $('#addGoodsCartForm').formSerialize(),
            beforeSend: function() {
                $('.button-buy-now').button('loading');
            },
            complete: function() {
                $('.button-buy-now').button('reset');
            },
            success: function(data) {
                if(data.status == 'true') {
                    if(!data.hasOwnProperty('inSpecGoods')) return window.location.href = '<?php echo $this->url('shop-checkout', ['action' => 'buyNow']); ?>';
                    else showMessage(data.message);
                } else {
                    if(data.hasOwnProperty('loginStatus') && data.loginStatus == 'false') {
                        return window.location.href = '<?php echo $this->url('shop-home'); ?>';
                    } else showMessage(data.message);
                }
            }
        });
    });

    <?php if($this->shopHelper()->shop('goods_consultation_state', 'goods') == 1) { ?>
    $(document).ready(function() {
        $("#<?php echo $cForm->getName(); ?>").validate({
            rules: {
                consultContent: {
                    required: true
                }
            },
            messages: {
                consultContent: {
                    required: "<?php echo $this->translate('请输入商品咨询内容!'); ?>"
                }
            },
            submitHandler:function(){
                submitConsultForm();
            }
        });
    });
    function submitConsultForm() {
        $.post("<?php echo $this->url('shop-goods', ['action'=>'addGoodsConsult']); ?>",$('#<?php echo $cForm->getName(); ?>').formSerialize(),
            function(data){
                if(data.status == 'true') {
                    $('#consultContent').val('');
                    showMessage('<?php echo $this->translate('您的咨询信息已经成功提交，卖家审核回复后，将正常显示!'); ?>');
                } else {
                    showMessage(data.message);
                }
            }, 'json');
    }
    //商品咨询列表
    dbshopAjaxList('<?php echo $this->url('shop-goods', ['action' => 'goodsConsultList', 'id' => $this->goodsInfo[0]->getGoodsId()]);?>', 'listGoodsAsk');
    <?php } ?>

    function selectGoodsSpec(specValueId, groupId) {
        if($('#spec_value_'+specValueId).attr('class') == 'coloractive') {
            $('#spec_value_'+specValueId).attr('class', '');

        } else {
            $('.goods_spec_'+groupId+' a').each(function() {
                $('#'+this.id).attr('class', '');
            });
            $('#spec_value_'+specValueId).attr('class', 'coloractive');
        }

        let specTagCount= $('#specTagIdCount').val();
        let specTagId   = [];
        $.each($('.goods_spec_tag_item a'), function () {
            if($('#'+this.id).attr('class') == 'coloractive') {
                specTagId.push(this.id.replace('spec_value_', ''));
            }
        });

        let specTagIdStr = specTagId.toString();
        if(specTagId.length == specTagCount && specTagIdStr != $('#specTagIdStr').val()) {
            let indexWait = layer.load(2);
            $.get("<?php echo $this->url('shop-goods', ['action' => 'ajaxGoodsPart', 'id' => $this->goodsInfo[0]->getGoodsId()]); ?>?tId="+specTagIdStr+'<?php if (isset($_GET['show']) && $_GET['show'] == 'dbshopPreview') echo '&show=dbshopPreview&time='.(isset($_GET['time']) ? intval($_GET['time']) : ''); ?>', {}, function (data) {
                if(data != '') {
                    $('#goods-part-body').html(data);
                    layer.close(indexWait);
                }
            });
            //window.location.href = "?tId="+specTagIdStr+"#spec";
        }
    }

    //加入对图片的延迟加载
    $('#goodsDesc img').each(function(){
        $(this).addClass('dbshopImgLoading');
        $(this).attr('data-original', $(this).attr('src'));

        $(this).css("max-width", 900);
        if(this.width>880) {
            $(this).css("max-width", '100%');
        }
    });
    $("img.dbshopImgLoading").lazyload({ effect : "fadeIn", skip_invisible : true, failure_limit : 1000 });

    //菜单置顶
    $(function() {
        if($('#sticky_navigation').html() != null) {
            var sticky_navigation_offset_top = $('#sticky_navigation').offset().top;
            var sticky_navigation = function(){
                var scroll_top = $(window).scrollTop();
                if (scroll_top > sticky_navigation_offset_top) {
                    $('#goodsSubBar').addClass('goods-sub-bar-play');
                } else {
                    $('#goodsSubBar').removeClass('goods-sub-bar-play');
                }
            };
            sticky_navigation();
            $(window).scroll(function() {
                sticky_navigation();
            });
        }
    });

    //商品收藏
    $(document).on('click', '#button-add-to-wishlist', function() {
        $.get("<?php echo $this->url('shop-goods', ['action' => 'addGoodsFavorites', 'id' => $this->goodsInfo[0]->getGoodsId()]); ?>", {}, function (data) {
            if(data.status == 'true') {
                if(data.favoritesState == 'add') {
                    $('#button-add-to-wishlist').removeClass('btn-dake');
                    $('#button-add-to-wishlist').addClass('btn-primary');
                }
                if(data.favoritesState == 'remove') {
                    $('#button-add-to-wishlist').addClass('btn-dake');
                    $('#button-add-to-wishlist').removeClass('btn-primary');
                }
            }
            showMessage(data.message);
        }, 'json');
    });

    //商品评价列表
    dbshopAjaxList('<?php echo $this->url('shop-goods', ['action' => 'goodsEvaluationList', 'id' => $this->goodsInfo[0]->getGoodsId()]);?>', 'listGoodsComment');

    <?php if (isset($this->showData['jsStr']) && !empty($this->showData['jsStr'])) echo $this->showData['jsStr']; ?>
</script>

